/**
 * 
 */
package org.gaming.prefab.thing.cost;

import java.util.ArrayList;
import java.util.List;

import org.gaming.prefab.thing.IThing;

/**
 * @author YY
 *
 */
public class CostReceipt<Num extends Number> {

	private final List<CostDetail> details = new ArrayList<>();
	//扩展数据，某个项目中用于冻结物品的记录
	private final List<IThing> extras = new ArrayList<>();
	//备注
	private String remark = "";
		
	public CostReceipt() {}
	
	public CostReceipt(List<? extends ICostThing<Num>> costThings) {
		for(ICostThing<Num> thing : costThings) {
			CostDetail detail = new CostDetail(thing.getThingId(), thing.getNumber());
			details.add(detail);
		}
	}
	
	public CostReceipt<Num> append(int thingId, Num num, Object extra) {
		CostDetail detail = new CostDetail(thingId, num, extra);
		details.add(detail);
		return this;
	}
	
	public void merge(CostReceipt<Num> costReceipt) {
		this.details.addAll(costReceipt.details);
	}
	
	public List<CostDetail> getDetails() {
		return details;
	}
	
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	public class CostDetail {
		private int thingId;
		private Num num;
		private Object extra;
		
		public CostDetail(int thingId, Num num, Object extra) {
			this.thingId = thingId;
			this.num = num;
			this.extra = extra;
		}
		public CostDetail(int thingId, Num num) {
			this(thingId, num, null);
		}
		
		public int getThingId() {
			return thingId;
		}
		public Num getNum() {
			return num;
		}
		public Object getExtra() {
			return extra;
		}
	}

	public List<IThing> getExtras() {
		return extras;
	}
}
